<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
  <style>
    .el-header img{
      vertical-align: middle;/*设置中间对齐*/
    }
    .el-header a{
      color: #666;
      text-decoration: none;
    }
    .el-table .el-table__cell{
      padding: 0;/*去掉自带的内边距*/
    }
    /*选择所有表格中的行 设置不换行*/
    .el-table .cell{
      white-space: nowrap;
      text-overflow: ellipsis;/*设置文本超出时 省略号*/
    }

  </style>
</head>
<body>
<div id="app">
  <el-container>
    <el-header height="150px">
      <div style="width: 1200px;margin: 0 auto">
        <img src="imgs/logo.png" width="300">
        <a href="">首页</a><el-divider direction="vertical"></el-divider>
        <a href="">热点资讯</a><el-divider direction="vertical"></el-divider>
        <a href="">商家入驻</a><el-divider direction="vertical"></el-divider>
        <a href="">社会招聘</a><el-divider direction="vertical"></el-divider>
        <a href="">校园招聘</a><el-divider direction="vertical"></el-divider>
        <a href="">帮助</a>
      </div>
      <!--导航菜单开始-->
      <div style="background-color: #0aa1ed">
        <el-menu style="width: 1200px;margin: 0 auto;border: 0" mode="horizontal" background-color="#0aa1ed"
                 text-color="#fff" active-text-color="#fff" @select="handleSelect">
          <el-menu-item v-for="c in categoryArr" :index="c.id">{{c.name}}</el-menu-item>

          <div style="float: right;position: relative;top: 10px">
            <el-input placeholder="请输入搜索的内容" @keydown.native.enter="search()" v-model="wd">
              <!--slot="append"作用是把按钮追加在文本框里面-->
              <el-button @click="search()" slot="append" icon="el-icon-search"></el-button>
            </el-input>
          </div>
        </el-menu>
      </div>
      <!--导航菜单结束-->
    </el-header>
    <el-main style="width: 1200px;margin: 0 auto">
      <el-row gutter="20">
        <el-col span="18">
          <!--轮播图开始-->
            <el-carousel height="300px">
              <el-carousel-item v-for="banner in bannerArr">
                <!--如果属性里面出现变量 必须使用属性绑定,也就是在属性名前面加:-->
                <img :src="banner.url" width="100%" height="100%">
              </el-carousel-item>
            </el-carousel>
          <!--轮播图结束-->
        </el-col>
        <el-col span="6">
          <!--排行榜开始-->
          <el-card>
            <h3>
              <i style="font-weight: bold" class="el-icon-trophy">销量最高</i>
            </h3>
            <el-divider></el-divider>
            <el-table :data="topArr">
              <el-table-column type="index" label="排名"></el-table-column>
              <el-table-column prop="title" label="标题"></el-table-column>
              <el-table-column prop="saleCount" label="销量"></el-table-column>
            </el-table>
          </el-card>
          <!--排行榜结束-->
        </el-col>
      </el-row>
    <!--商品列表开始-->
      <el-row gutter="20">
        <el-col span="6" v-for="p in productArr">
          <el-card>
            <a :href="'/detail.html?id='+p.id">
              <img :src="p.url" width="100%" height="233">
            </a>
            <p style="font-size: 14px;height: 30px">
              <a :href="'/detail.html?id='+p.id">
                {{p.title}}
              </a>
            </p>
            <p style="font-size: 12px">
              <b>￥{{p.price}}</b> <s>{{p.oldPrice}}</s>
              <span style="float: right">销量:{{p.saleCount}}件</span>
            </p>
          </el-card>
        </el-col>
      </el-row>
    <!--商品列表结束-->
    </el-main>
    <el-footer>
      <div style="background-image: url('imgs/wave.png');height: 90px"></div>
      <div style="background-color: #3f3f3f;text-align: center;
      color: #b1b1b1;padding: 30px 0">
        <p>Copyright © 北京达内金桥科技有限公司版权所有 京ICP备12003709号-3 京公网安备 11010802029572号</p>
        <p>涵盖20余门课程体系，致力于打造权威的IT职业教育学习平台</p>
        <p>达内在线WWW.TMOOC.CN 专注于IT职业技能培训</p>
      </div>
    </el-footer>
  </el-container>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
 let v = new Vue({
    el: '#app',
    data: function() {
      return {
        categoryArr: [],
        bannerArr:[],
        topArr:[],
        productArr:[],
        wd:""
      }
    },
   methods:{
     handleSelect(key,keyPath){
       //跳转到结果页面并把分类的id传递过去
       location.href = "/result.html?id="+key;
     },
     search(){
       location.href = "/result.html?wd="+v.wd;
     }
   },
   created:function () {
      //请求所有分类的信息
     axios.get("/category/select").then(function (response) {
       v.categoryArr = response.data;
     })
     //请求所有轮播图信息
     axios.get("/banner/select").then(function (response) {
       v.bannerArr = response.data;
     })
     //请求所有的商品信息
     axios.get("/product/selectForIndex").then(function (response) {
       v.productArr = response.data;
     })
     //请求排行榜数据
     axios.get("/product/selectForTop").then(function (response) {
       v.topArr = response.data;
     })
   }
  })
</script>
</html>